def q(b):
    p=0
    for i in range(2, b):
        if b % i == 0:
            p=p+1
    if p>0:
        return 0
    else:
        return b

c=int(input())
c1=c//1000
c2=c//100%10
c3=c//10%10
c4=c%10
l=0

if 999<c<10000:
    z=c1
    p=q(z)
    if p>l:
        l=p
    z=c2
    p=q(z)
    if p>l:
        l=p
    z=c3
    p=q(z)
    if p>l:
        l=p
    z=c4
    p=q(z)
    if p>l:
        l=p
    z=c1*10 + c2
    p=q(z)
    if p>l:
        l=p
    z=c2*10 + c3
    p=q(z)
    if p>l:
        l=p
    z=c3*10 +c4
    p=q(z)
    if p>l:
        l=p
    z=c1*100 + c2*10 + c3
    p=q(z)
    if p>l:
        l=p
    z=c2*100 +c3*10 + c4
    p=q(z)
    if p>l:
        l=p
    z=c
    p=q(z)
    if p>l:
        l=p

print(l)
